package cn.ml.lambda;


/*
 推到lambda表达式
 */
public class LambdaDemo1 {

    //3、静态内部类
    static class LikeImpl2 implements Like{
        @Override
        public void lambda() {
            System.out.println("i like lambda222");
        }
    }

    public static void main(String[] args) {
        Like likeDao = new ILikeImpl();
        likeDao.lambda();

        Like likeDao2 = new LikeImpl2();
        likeDao2.lambda();

        //4、局部内部类
        class ILikeImpl3 implements Like{
            @Override
            public void lambda() {
                System.out.println("i like lambda333");
            }
        }
        Like likeDao3 = new ILikeImpl3();
        likeDao3.lambda();

        //5、匿名内部类（没有类名称）,必须借助接口或父类
        Like likeDao4 = new Like() {
            @Override
            public void lambda() {
                System.out.println("i like lambda444");
            }
        };
        likeDao4.lambda();

        //6、使用lambda简化(只要接口中方法)
        Like likeDao5 = ()-> {
            System.out.println("i like lambda555");
        };
        likeDao5.lambda();
    }
}

//1、定义一个函数式接口：接口中只有一个方法
interface Like{
    void lambda();
}

//2、实现类
class ILikeImpl implements Like{
    @Override
    public void lambda() {
        System.out.println("i like lambda111");
    }
}
